home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / presto / prest_04.lha / src / stack.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-06  |  1.3 KB  |  63 lines

  1. //
  2. // Stack maintenance
  3. //
  4. //
  5.  
  6.  
  7. #define MINSTACKSIZEXP    (10)
  8. #define ONEK        (1<<10)
  9. #define MINSTACKSIZ    (1<<MINSTACKSIZEXP)        /* 1k */
  10. #define DEFSTACKSIZ    (MINSTACKSIZ << 3)        /* 4k */
  11. #define MAXSTACKSIZ    (MINSTACKSIZ << 10)        /* 1Mb */
  12.  
  13. //
  14. // Return how many integral chunks of MINSTACKSIZES fit in the 
  15. // requested stacksize
  16. //
  17. #define STACKSIZTOMINCHUNKS(sz)    (sz >> MINSTACKSIZEXP)
  18.  
  19. class Stack;
  20. //
  21. // We keep a stack of free stacks.  When we need a new stack, we
  22. // move downward, trying to find the right size (or bigger).  The intention
  23. // is that what we need will be near the top, since we are likely to be
  24. // asking for something that we asked for before.  This won't always
  25. // hold, but its just as cheap to use a stack as anything else.
  26. // 
  27.  
  28.  
  29. #define MAXFREESTACKS        100        
  30.  
  31. class FreeStacks    {
  32.     Stack* fs_free[MAXFREESTACKS];
  33.     int   fs_sp;
  34.     Spinlock *fs_lock;
  35. public:
  36.     FreeStacks();
  37.     ~FreeStacks();
  38.     Stack *find(int sz);
  39.     void free(Stack*);
  40. };
  41.  
  42.         
  43. class Stack    {
  44.     int *st_base;        // bottom of stack
  45.     int st_size;        // what user thinks
  46.     int st_limit;        // what we really are
  47. public:
  48.     Stack(int size);
  49.     ~Stack();
  50.     int size()
  51.         { return st_size; }        
  52.     int limit()
  53.         { return st_limit;}
  54. /* XX machdep */        
  55.     int *top()
  56.         { return  (int*)(((int)st_base + st_limit - 4) & ~03);}
  57.     void destroy()
  58.         { delete st_base; }
  59.     int numstacksbuilt();
  60. };
  61.  
  62.  
  63.